#include "model.h"

Model::Model(QObject *parent) :
    QAbstractTableModel(parent)
{
    header_data
            <<QString::fromUtf8("1")
           <<QString::fromUtf8("2")
          <<QString::fromUtf8("3")
         <<QString::fromUtf8("4")
        <<QString::fromUtf8("5")
       <<QString::fromUtf8("6")
      <<QString::fromUtf8("7")
     <<QString::fromUtf8("8")
    <<QString::fromUtf8("9")
    <<QString::fromUtf8("10")
    <<QString::fromUtf8("11");
    for(int i = 0; i <20; i++)
    {
        Item* itm = new Item;
        list.append(itm);
    }

}

QVariant Model::data(const QModelIndex &index, int role) const
{
    QString design;
    QString type;
    QString unit;
    QString desc;
    QList<float> data;
    if (!index.isValid())
        return QVariant();

    if (index.row() >= list.size())
        return QVariant();
    // для каждого столбца возвращаем нужные данные
    if (role == Qt::DisplayRole ){
        if (index.column() == 0 )
            return list.at(index.row())->design;
        if (index.column() == 1 )
            return list.at(index.row())->type;
        if (index.column() == 2 )
            return list.at(index.row())->unit;
        if (index.column() == 3 )
            return list.at(index.row())->data[0];
       if (index.column() == 4 )
            return list.at(index.row())->data[1];
        if (index.column() == 5 )
            return list.at(index.row())->data[2];
        if (index.column() == 6 )
            return list.at(index.row())->data[3];
        if (index.column() == 7 )
            return list.at(index.row())->data[4];
        if (index.column() == 8 )
            return list.at(index.row())->data[5];
        if (index.column() == 9 )
            return list.at(index.row())->data[6];
        if (index.column() == 10 )
            return list.at(index.row())->data[7];
    }
    return QVariant();
}

int Model::rowCount(const QModelIndex &parent) const
{
    return 10;
}

int Model::columnCount(const QModelIndex &parent) const
{
    return 3;
}

QVariant Model::headerData(int section, Qt::Orientation orientation, int role) const
{
    if(orientation == Qt::Horizontal && role == Qt::DisplayRole)
        return header_data.at(section);
    else
        return QVariant();
}
